#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution
{
public:
    int findBottomLeftValue(TreeNode* root)
    {
        PrevOrder(root, 1);
        return _leftVal;
    }

private:
    void PrevOrder(TreeNode* root, int high)
    {
        if (root == nullptr) {
            return;
        }

        if (high > _maxHigh)
        {
            _leftVal = root->val;
            _maxHigh = high;
        }

        PrevOrder(root->left, high + 1);
        PrevOrder(root->right, high + 1);
    }

    int _maxHigh = 0;
    int _leftVal = 0;
};